Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(x/): use cosmossdk.io/core/codec instead of github.com/cosmos/cosmos-sdk/codec #23313

Merged
merged 4 commits into from
Jan 13, 2025

Conversation

caseylove
Copy link
Contributor

@caseylove caseylove commented Jan 10, 2025

Description

Closes: #23253

Also, this PR is a supplementary of #23300 for test files

Summary by CodeRabbit

Based on the comprehensive summary of changes, here are the release notes:

Release Notes

  • Codec Migration

    • Updated codec imports from github.com/cosmos/cosmos-sdk/codec to cosmossdk.io/core/codec across multiple modules
    • Standardized codec usage and dependency management
  • Error Handling Improvements

    • Enhanced error handling in JSON marshaling and unmarshaling processes
    • Replaced MustMarshalJSON and MustUnmarshalJSON with explicit error checking
    • Added more robust panic mechanisms with error context
  • Modules Affected

    • Accounts
    • Bank
    • Circuit
    • Consensus
    • Distribution
    • Epochs
    • Evidence
    • Feegrant
    • Genutil
    • Group
    • Mint
    • NFT
    • Protocol Pool
    • Slashing
    • Staking
  • Key Changes

    • More explicit error management during genesis state processing
    • Improved error reporting for codec-related operations
    • Consistent error handling across different modules

@caseylove caseylove requested a review from a team as a code owner January 10, 2025 09:29
Copy link
Contributor

coderabbitai bot commented Jan 10, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This pull request introduces a comprehensive update to codec imports and error handling across multiple modules in the Cosmos SDK. The changes primarily involve replacing codec imports from github.com/cosmos/cosmos-sdk/codec with cosmossdk.io/core/codec and enhancing error handling mechanisms. Modules affected include accounts, bank, distribution, evidence, feegrant, genutil, group, mint, nft, protocolpool, slashing, staking, and others. The modifications focus on more explicit error checking during JSON marshaling and unmarshaling operations, replacing MustMarshalJSON and MustUnmarshalJSON with methods that allow for explicit error handling.

Changes

File Path Change Summary
x/*/module.go Updated codec imports, modified DefaultGenesis() with explicit error handling
x/*/types/genesis.go Replaced codec imports, enhanced error handling in genesis state methods
x/*/simulation/decoder.go Updated codec imports, replaced MustUnmarshal with Unmarshal and added error checks
x/*/migrations/*/migrate.go Updated codec imports, improved error handling in migration functions

Suggested labels

C:codec, C:error-handling, T:refactoring

Suggested reviewers

  • tac0turtle
  • aljo242
  • lucaslopezf

Possibly related PRs


📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0f05e5 and c420842.

📒 Files selected for processing (32)
  • x/accounts/module.go (2 hunks)
  • x/bank/types/genesis.go (2 hunks)
  • x/bank/v2/module.go (2 hunks)
  • x/circuit/module.go (2 hunks)
  • x/consensus/module.go (1 hunks)
  • x/distribution/migrations/v4/migrate.go (2 hunks)
  • x/distribution/module.go (2 hunks)
  • x/distribution/simulation/decoder.go (2 hunks)
  • x/epochs/module.go (2 hunks)
  • x/evidence/module.go (2 hunks)
  • x/feegrant/migrations/v2/store.go (1 hunks)
  • x/feegrant/module/module.go (2 hunks)
  • x/feegrant/simulation/decoder.go (2 hunks)
  • x/genutil/depinject.go (1 hunks)
  • x/genutil/module.go (3 hunks)
  • x/genutil/types/genesis_state.go (3 hunks)
  • x/group/internal/orm/types.go (1 hunks)
  • x/group/keeper/genesis.go (1 hunks)
  • x/group/module/module.go (2 hunks)
  • x/group/simulation/decoder.go (2 hunks)
  • x/mint/module.go (2 hunks)
  • x/nft/module/module.go (2 hunks)
  • x/nft/simulation/decoder.go (2 hunks)
  • x/protocolpool/module.go (2 hunks)
  • x/slashing/migrations/v4/migrate.go (3 hunks)
  • x/staking/migrations/v5/store.go (1 hunks)
  • x/staking/migrations/v6/store.go (1 hunks)
  • x/staking/module.go (3 hunks)
  • x/staking/simulation/decoder.go (3 hunks)
  • x/staking/types/delegation.go (4 hunks)
  • x/staking/types/genesis.go (2 hunks)
  • x/staking/types/validator.go (2 hunks)

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
x/accounts/internal/implementation/implementation.go (1)

Line range hint 19-24: Consider updating the interface definition.

The LegacyStateCodec interface could be updated to use the new codec.Codec type directly instead of defining the interface inline.

-	LegacyStateCodec interface {
-		Marshal(gogoproto.Message) ([]byte, error)
-		Unmarshal([]byte, gogoproto.Message) error
-	}
+	LegacyStateCodec codec.Codec
x/accounts/defaults/multisig/utils_test.go (1)

Line range hint 29-126: Consider simplifying the mock implementation.

While the implementation is thorough, most methods panic with "unimplemented". Consider:

  1. Using a more focused mock that only implements the required methods
  2. Adding TODO comments for methods that might be needed in future tests
type mockStateCodec struct {
	codec.Codec
}

-// GetMsgAnySigners implements codec.Codec.
-func (mockStateCodec) GetMsgAnySigners(msg *types.Any) ([][]byte, protoreflect.Message, error) {
-	panic("unimplemented")
-}
-// ... (remove other unimplemented methods)

// Only keep the methods that are actually used
func (c mockStateCodec) Marshal(m gogoproto.Message) ([]byte, error) {
	if m == nil || gogoproto.Size(m) == 0 {
		return []byte{}, nil
	}
	return gogoproto.Marshal(m)
}

func (c mockStateCodec) Unmarshal(bz []byte, ptr gogoproto.Message) error {
	return gogoproto.Unmarshal(bz, ptr)
}

// TODO: Implement other methods as needed for future tests
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 517839b and c0f05e5.

📒 Files selected for processing (4)
  • x/accounts/defaults/base/utils_test.go (1 hunks)
  • x/accounts/defaults/lockup/utils_test.go (1 hunks)
  • x/accounts/defaults/multisig/utils_test.go (1 hunks)
  • x/accounts/internal/implementation/implementation.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
x/accounts/defaults/base/utils_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/defaults/lockup/utils_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/defaults/multisig/utils_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/accounts/internal/implementation/implementation.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-system-v2
  • GitHub Check: Analyze
  • GitHub Check: Summary
🔇 Additional comments (6)
x/accounts/defaults/base/utils_test.go (2)

12-12: LGTM: Import change aligns with the PR objective.

The transition to cosmossdk.io/core/codec is correctly implemented.


Line range hint 27-41: LGTM: Robust implementation of mockStateCodec.

The implementation correctly handles:

  • Nil message cases
  • Empty message cases
  • Proper marshaling/unmarshaling
x/accounts/defaults/lockup/utils_test.go (2)

13-13: LGTM: Consistent import update.

The import change aligns with the PR objective and maintains consistency with other files.


Line range hint 28-42: LGTM: Consistent mockStateCodec implementation.

The implementation maintains consistency with other test files and properly handles edge cases.

x/accounts/internal/implementation/implementation.go (1)

12-12: LGTM: Clean import update.

The transition to cosmossdk.io/core/codec is properly implemented in this core file.

x/accounts/defaults/multisig/utils_test.go (1)

15-15: LGTM: Consistent import update.

The import change aligns with the PR objective and maintains consistency across the codebase.

@tac0turtle
Copy link
Member

seems like a few tests are failing, can you look into them

@caseylove
Copy link
Contributor Author

seems like a few tests are failing, can you look into them

Thanks, I'm going to check this

@tac0turtle
Copy link
Member

could you please merge all your prs making the same change in other repos into this pr. It helps reduce the amount of reviews needed

@caseylove
Copy link
Contributor Author

caseylove commented Jan 10, 2025

could you please merge all your prs making the same change in other repos into this pr. It helps reduce the amount of reviews needed

@tac0turtle Hi sir, how about combining all these PRs into three PRs?

@aljo242
Copy link
Contributor

aljo242 commented Jan 10, 2025

could you please merge all your prs making the same change in other repos into this pr. It helps reduce the amount of reviews needed

@tac0turtle Hi sir, how about combining all these PRs into three PRs?

@caseylove just combining all into one (this PR) would be best

@caseylove
Copy link
Contributor Author

could you please merge all your prs making the same change in other repos into this pr. It helps reduce the amount of reviews needed

@tac0turtle Hi sir, how about combining all these PRs into three PRs?

@caseylove just combining all into one (this PR) would be best

Okay, I will work on this tomorrow.

@caseylove caseylove force-pushed the chore/accounts-codec branch from 294f767 to c420842 Compare January 13, 2025 03:26
@caseylove
Copy link
Contributor Author

@julienrbrt Hi sir, I have picked other PRs' commits into this PR

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Jan 13, 2025
@julienrbrt julienrbrt added this pull request to the merge queue Jan 13, 2025
@julienrbrt julienrbrt removed this pull request from the merge queue due to a manual request Jan 13, 2025
@julienrbrt julienrbrt changed the title chore(x/accounts): use cosmossdk.io/core/codec instead of github.com/cosmos/cosmos-sdk/codec chore(x/): use cosmossdk.io/core/codec instead of github.com/cosmos/cosmos-sdk/codec Jan 13, 2025
@julienrbrt julienrbrt added this pull request to the merge queue Jan 13, 2025
Merged via the queue into cosmos:main with commit bc9ce39 Jan 13, 2025
72 of 76 checks passed
mergify bot pushed a commit that referenced this pull request Jan 13, 2025
…s/cosmos-sdk/codec` (#23313)

(cherry picked from commit bc9ce39)

# Conflicts:
#	x/bank/v2/module.go
#	x/mint/module.go
julienrbrt added a commit that referenced this pull request Jan 13, 2025
…s/cosmos-sdk/codec` (backport #23313) (#23340)

Co-authored-by: caseylove <[email protected]>
Co-authored-by: Julien Robert <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use cosmossdk.io/core/codec
4 participants